from itertools import groupby

from app.models.space import SpaceModel


def group_by_v(data):
    data_list = []
    if not data:
        data_list.append({"value": 1, "name": '暂无数据'})
        return data_list

    for i, j in groupby(data, key=lambda x: x.space_id):
        data_list.append({"space_id": i, "value": len(list(j)), "name": SpaceModel().get_s_name(i)})
    return data_list
